package cn.edu.nju.askme.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import cn.edu.nju.askme.dao.IUserDAO;
import cn.edu.nju.askme.model.User;
import cn.edu.nju.askme.service.IUserService;
@Component
public class UserService implements IUserService{
	private IUserDAO userDAO;

	public IUserDAO getUserDAO() {
		return userDAO;
	}
	@Resource
	public void setUserDAO(IUserDAO userDAO) {
		this.userDAO = userDAO;
	}

	public User check(String loginName) {
		List<User> userByName = userDAO.findByUsername(loginName);
		List<User> userByEmail = userDAO.findByEmail(loginName);
		if(userByName.size()>0)
			return userByName.get(0);
		if(userByEmail.size()>0)
			return userByEmail.get(0);
		return null;
	}
	public void add(User user) {
		userDAO.save(user);
	}
}
